package me.acomma.groot.domain.user;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public enum Gender {
    MALE("M"),
    FEMALE("F");

    private String code;

    Gender(String code) {
        this.code = code;
    }

    public String code() {
        return this.code;
    }

    public static Gender code(final String code) {
        List<Gender> genders = Arrays.stream(Gender.values())
                .filter(gender -> gender.code.equals(code))
                .collect(Collectors.toList());
        if (genders == null || genders.size() == 0) {
            return null;
        }
        return genders.get(0);
    }
}
